package dao

import (
	"context"
	"fmt"
	"server/basic/config"
	"server/basic/model"
	"time"
)

func RedisPhone(phone string, i int) bool {
	key := fmt.Sprintf("login:%s", phone)
	err := config.Rdb.Set(context.Background(), key, i, 2*time.Minute).Err()
	if err != nil {
		return false
	}
	return true
}

func RedisList(list []model.Courses) bool {
	key := fmt.Sprintf("create")
	for _, courses := range list {
		err := config.Rdb.HSet(context.Background(), key, courses).Err()
		if err != nil {
			return false
		}

	}
	return true
}

func RedisListS() (consur string, err error) {
	key := fmt.Sprintf("create")
	result, err := config.Rdb.Get(context.Background(), key).Result()
	if err != nil {
		return "", err
	}
	return result, nil
}
